package com.yyfax.ph.personal.mymoney.withdraw;


import android.text.TextUtils;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.IView;
import com.yyfax.infrastructure.mvp.Presenter;
import com.yyfax.infrastructure.mvp.PresenterFactory;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * 提现presenter
 */

public class WithDrawPresenter extends Presenter<WithDrawModel, WithDrawPresenter.View> {

	private View mView;


	public static class Generator implements PresenterFactory<WithDrawPresenter> {
		@Override
		public WithDrawPresenter create() {
			return new WithDrawPresenter();
		}
	}

	@Override
	public void attach(View view) {
		mView = view;
		mModel = new WithDrawModel();
		EventAgent.register(this);
	}

	@Override
	public void detach() {
		mView = null;
		mModel = null;
		EventAgent.unregister(this);
	}


	public interface View extends IView {
		void withdrawSuccess(String tips);

		void withdrawFailure(String tips);
	}

	public void withdraw(String money) {
		execute(new WithDrawModel.Money(money));
	}

	@Subscribe(threadMode = ThreadMode.MAIN)
	public void withdrawResult(WithDrawModel.WithdrawResult result) {
		if (isResponseSuccess(result)) {
			mView.withdrawSuccess(TextUtils.isEmpty(result.getMsg()) ? "提现成功" : result.getMsg());
		} else {
			mView.withdrawFailure(TextUtils.isEmpty(result.getMsg()) ? "提现失败" : result.getMsg());
		}
	}

}
